package com.vision.world.survey.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.vision.world.survey.R;

/**
 * Created by Ada on 2017/10/11.
 */

public class LayerSettingAdapter extends BaseAdapter {
    private LayoutInflater mInflater;

    /**
     * layer设置图标,未选中
     */
    public static final int[] layerSettingGVIcons = {R.drawable.map_mode_normal,
            R.drawable.map_mode_satellite};

    /**
     * layer设置名称
     */
    public static final String[] layerSettingGVNames = {"标准地图",   "卫星地图"};

    public static int checkIndex = 1;

    public LayerSettingAdapter(Context context){
        this.mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_gv_layer_setting_layout, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        ViewHolder holder = (ViewHolder) convertView.getTag();

        holder.info.setText(layerSettingGVNames[position]);
        if (checkIndex==position) {
            holder.rlImgBg.setBackgroundResource(layerSettingGVIcons[position]);
            holder.photo.setImageResource(R.drawable.map_skin_item_select_pic_green);
            holder.photo.setVisibility(View.VISIBLE);
//            holder.photo.setBackgroundResource(layerSettingGVIcons[position]);
//            holder.rl_photo.setBackground(convertView.getResources().getDrawable(R.drawable.map_item_bg2));
        } else {
            holder.rlImgBg.setBackgroundResource(layerSettingGVIcons[position]);
            holder.photo.setVisibility(View.GONE);
        }
        return convertView;
    }

    static class ViewHolder {
        final ImageView photo;
        final TextView info;
        final RelativeLayout rlImgBg;
        ViewHolder(View view) {
            photo = (ImageView) view.findViewById(R.id.map_item_image);
            info = (TextView) view.findViewById(R.id.map_item_name);
            rlImgBg=(RelativeLayout)view.findViewById(R.id.rl_img_bg);
        }
    }
}
